<?php
/**
 * Bootstraps application
 * 
 * @author paq
 *
 */
class Bootstrap
{
	public function __construct()
	{
		require_once('Autoloader.php');
		
		$this->initTimeZone();
		$this->initPropel();
		$this->initMagicQuotes();
		$this->initSession();
	}
	
	/**
	 * Initialize time zone
	 * 
	 * @return void
	 */
	protected function initTimeZone()
	{
		date_default_timezone_set('Europe/Warsaw');
	}
	
	/**
	 * Initializes Propel
	 * 
	 * @return void
	 */
	protected function initPropel()
	{
		try {
			$propelClassesPath = realpath(LIB_PATH . '/propel/classes');
			$propelPath = realpath(LIB_PATH . '/propel');
			set_include_path($propelClassesPath . PATH_SEPARATOR . get_include_path());
			set_include_path($propelPath . PATH_SEPARATOR . get_include_path());
			
			require_once('propel/Propel.php');
			Propel::init(LIB_PATH . '/propel/conf/-conf.php');
			
			$con = Propel::getConnection();
			$con->query('SET NAMES `UTF8`;');
		} catch (Exception $e) {
			throw new Exception('Propel could not be initialized. ' . $e->getMessage());
		}
	}
	
	// TODO: clear slashes
	protected function initMagicQuotes()
	{
		if (get_magic_quotes_gpc()) {
			foreach ($_POST as $k => $v) { 
				$_POST[$k] = stripslashes($v);
			}
			
			foreach ($_GET as $k => $v) {
				$_GET[$k] = stripslashes($v);
			}
		}
	}
	
	protected function initSession()
	{
		session_start();
	}
}